import { ref, computed } from 'vue'
import { defineStore } from 'pinia'

export const useMapStore = defineStore('map', () => {
  //拉框查询中的标注图层
  let find_source = null;
  let find_layer = null;
  //热力图层
  let heatMapSource=null;
  let heatMapLayer = null;

  let high_source = null;
  let high_layer = null;
  const tableData = ref([])
  //事件状态码
  const statusOrder={
    '未处理':0,
    '进行中':1,
    '已处理':2,
  }
  // 表格数据排序(根据状态码)
  // 升序
  const sortTableDataUp = () => {
    tableData.value = tableData.value.slice().sort((a, b) => {
      const statusA = a.AttValue[7];
      const statusB = b.AttValue[7];
      return statusOrder[statusA] - statusOrder[statusB];
    });
  };
  // 降序
  const sortTableDataDown = () => {
    tableData.value = tableData.value.slice().sort((a, b) => {
      const statusA = a.AttValue[7];
      const statusB = b.AttValue[7];
      return statusOrder[statusB] - statusOrder[statusA];
  })
}
//恢复初始顺序
  const refreshTableData = () => {
    tableData.value = tableData.value.slice().sort((a, b) => {
      const timeA = new Date(a.AttValue[3].replace(/\./g, '-')).getTime();
      const timeB = new Date(b.AttValue[3].replace(/\./g, '-')).getTime();
      return timeA - timeB;
    });
  }
  const setTableData = (data) => {
    tableData.value = data
  }
  //当前选中功能索引
  const currentIndex = ref(0)
  const setCurrentIndex = (index) => {
    currentIndex.value = index
  }
  //组件显示
  const passWordShow=ref(false)
  const setPasswordShow= (val) => {
    passWordShow.value=val
  }
  const eventTableShow=ref(false)
  const setEventTableShow= (val) => {
    eventTableShow.value=val
  }

  const eventCountChartShow=ref(false)
  const setEventCountChartShow= (val) => {
    eventCountChartShow.value=val
  }
  return {
    find_source,
    find_layer,
    heatMapSource,
    heatMapLayer,
    tableData,
    setTableData,
    currentIndex,
    setCurrentIndex,
    passWordShow,
    setPasswordShow,
    eventTableShow,
    setEventTableShow,
    eventCountChartShow,
    setEventCountChartShow,
    sortTableDataUp,
    sortTableDataDown,
    refreshTableData,

  }
})

